﻿using System;
using System.Collections;
using System.Windows.Data;

namespace BusinessIntelligenceToolkit.ViewModels
{
    public class NavigableListCollectionView : ListCollectionView
    {
        public NavigableListCollectionView(IList list) : base(list)
        {
        }

        public event EventHandler BringCurrentIntoView;


        public bool MoveCurrentToFirstWithBringing()
        {
            var sucess = MoveCurrentToFirst();
            if (sucess)
            {
                RaiseBringCurrentIntoView();
            }

            return sucess;
        }

        public bool MoveCurrentToLastWithBringing()
        {
            var sucess = MoveCurrentToLast();
            if (sucess)
            {
                RaiseBringCurrentIntoView();
            }

            return sucess;
        }

        public bool MoveCurrentToNextWithBringing()
        {
            var sucess = MoveCurrentToNext();
            if (sucess)
            {
                RaiseBringCurrentIntoView();
            }

            return sucess;
        }

        public bool MoveCurrentToPreviousWithBringing()
        {
            var sucess = MoveCurrentToPrevious();
            if (sucess)
            {
                RaiseBringCurrentIntoView();
            }

            return sucess;
        }

        public bool MoveCurrentToWithBringing(object item)
        {
            var sucess = MoveCurrentTo(item);
            if (sucess)
            {
                RaiseBringCurrentIntoView();
            }

            return sucess;
        }

        private void RaiseBringCurrentIntoView()
        {
            if (BringCurrentIntoView != null)
            {
                BringCurrentIntoView(this, EventArgs.Empty);
            }
        }
    }
}